

<div class="layui-form" lay-filter="layuiadmin-form-useradmin" style="padding: 20px 0 0 0;">
  <div class="layui-form-item">
    <label class="layui-form-label">用户名</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="username" value="{{ d.params.username || '' }}" lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">密码</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="password" name="password" value="{{ d.params.password || '' }}" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item" >
    <label class="layui-form-label">角色</label>
    <script type="text/html" template>
      <div class="layui-input-block" id="checkboxdata">
        {{# console.log(d.params.role)}}
      </div>
    </script>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">岗位</label>
    <div class="layui-input-inline">
      <select name="post" lay-verify="required">
        <option value=""></option>
        <option value="0">开发岗</option>
        <option value="1">运维岗</option>
        <option value="2">管理岗</option>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">手机号码</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="phone" value="{{ d.params.phone || '' }}" lay-verify="phone" placeholder="请输入号码" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">邮箱</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="email" value="{{ d.params.email || '' }}" lay-verify="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>

  <div class="layui-form-item" lay-filter="sex">
    <label class="layui-form-label">选择性别</label>
    <div class="layui-input-block">
      <script type="text/html" template>
        <input type="radio" name="sex" value="男" title="男" {{ d.params.sex === '男' ? 'checked' : '' }}>
        <input type="radio" name="sex" value="女" title="女" {{ d.params.sex === '女' ? 'checked' : '' }}>
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline">
      <input type="button" lay-submit lay-filter="LAY-user-front-submit" value="确认" class="layui-btn">
    </div>
  </div>
</div>

<script>
layui.use(['admin', 'form', 'upload'], function(){
  var $ = layui.$
  ,form = layui.form
  ,upload = layui.upload;
  // 动态获取角色信息
  $(function () {
    $.ajax({
      url: "./json/checkboxdata.js",
      type:'post',
      dataType:'json',
      success:function (res) {
        var s = [];
        if (res.code == 0){
          for (let i = 0; i < res.data.length; i++) {
            s.push(`<input type='checkbox' name='${res.data[i].name}' title='${res.data[i].name}' {{ d.params.role.indexOf('${res.data[i].name}')!=-1 ? 'checked' : '' }} > `)
          }
          $('#checkboxdata').append(s.join(""));
          console.log("结果数组====》" + s)
          form.render();

        }


      }
    })
  })
  //上传头像
  upload.render({
    elem: '#layuiadmin-upload-useradmin'
    ,url: './json/upload/demo.js'
    ,accept: 'images'
    ,method: 'get'
    ,acceptMime: 'image/*'
    ,done: function(res){
      $(this.item).prev("div").children("input").val(res.data.src)
    }
  });
})
</script>